'''
Created on Feb 19, 2011

@author: inyaky
'''
from google.appengine.ext import db
from model.fields.uDateTimeTaskField import DateTimeTaskField
import datetime
import uConst

class DeadLineTaskField(DateTimeTaskField):

    _message = db.StringProperty()
    
    def setMessage(self, aMessage):
        self._message = aMessage
        self.put()
        
    def getMessage(self):
        return self._message
    
    def toCalendar(self):
        if self._value: 
            cad = '{ "Date": "new Date(_anio_, _mes_, _dia_)", "Title": "_titulo_", "CssClass": "calendar_deadline" },'
            cad = cad.replace('_anio_', self.getValue().strftime("%Y"))
            cad = cad.replace('_mes_', str(self.getValue().month - 1))
            cad = cad.replace('_dia_', self.getValue().strftime("%d"))
            cad = cad.replace('_titulo_', self.getTaskOwner().getName() + ', ' + self.getName())
            return cad
    
    def toRenderable(self):
        if self._value:
            val = datetime.datetime.strftime(self.getValue(), uConst.SWM_DATETIME_FORMAT)
            exp = self.getValue() < datetime.datetime.today()
        else:
            val = ''
            exp = False
        
        if self.getRequired():
            validators = 'required'
        else:
            validators = ''
        
        return [{'fname':self.getName(), 'fvalue':val, 'ftype':self.__class__.__name__, 'fkey':self.key(), 'fmessage':self.getMessage(), 'expired':exp, 'fvalidators':validators}]
        
